/**
* Class representing a single declared non-ui resource for this plugin component
*/
jsx3.lang.Class.defineClass(
        "tibco.admin.util.component.Resource",
        jsx3.lang.Object,
        null,
        function(config) {

            /**
            * {String} The path to the resource (relative to the plugin's contextRoot)
            * @private
            */
            config.prototype.path = null;

            /**
            * {String} Description of the resource
            * @private
            */
            config.prototype.description = null;

            /**
            * {String} the type of the resource
            */
            config.prototype.type = null;

            /**
            * {String} If the <code>type</code> of this resource is <code>script</code>, the name of the class it represents
            * @private
            */
            config.prototype.className = null;

            /**
             * Constructor for this class.
             *
             * @param doc {jsx3.xml.Entity} an xml node containing the information for a single resource of a plugin component
             * @throws {tibco.admin.exception.InvalidComponentSchemaException} if the xml is invalid
             */
            config.prototype.init = function(doc) {
                this.jsxsuper();
                var children = doc.getChildNodes().iterator();
                while(children.hasNext()) {
                    var child = children.next();
                    var childName = child.getNodeName();
                    if(childName == "path") {
                        this.path = child.getValue();
                    }
                    else if(childName == "description") {
                        this.description = child.getValue();
                    }
                    else if(childName == "type") {
                        this.type = child.getValue();
                    }
                    else if(childName == "class_name") {
                        this.className = child.getValue();
                    }
                }
                if(!this.path) {
                    throw new tibco.admin.exception.InvalidComponentSchemaException("Tag 'path' is a required child of the 'resource' tag.")
                }
                if(jsx3.util.strTrim(this.path.trim()) == "") {
                    throw new tibco.admin.exception.InvalidComponentSchemaException("Tag 'path' may not be empty.")
                }
                if(!this.description) {
                    throw new tibco.admin.exception.InvalidComponentSchemaException("Tag 'description' is a required child of the 'resource' tag.")
                }
                if(jsx3.util.strTrim(this.description.trim()) == "") {
                    throw new tibco.admin.exception.InvalidComponentSchemaException("Tag 'description' may not be empty.")
                }
                if(!this.type) {
                    throw new tibco.admin.exception.InvalidComponentSchemaException("Tag 'type' is a required child of the 'resource' tag.")
                }
                if(jsx3.util.strTrim(this.type.trim()) == "") {
                    throw new tibco.admin.exception.InvalidComponentSchemaException("Tag 'type' may not be empty.")
                }
                if((this.type == "script") || (this.path.indexOf(".js") != -1)) {
                    if(!this.className) {
                        throw new tibco.admin.exception.InvalidComponentSchemaException("Tag 'class_name' is a required child of the 'resource' tag for javascript resources.")
                    }
                    if(jsx3.util.strTrim(this.className.trim()) == "") {
                        throw new tibco.admin.exception.InvalidComponentSchemaException("Tag 'class_name' may not be empty for javascript resources.")
                    }
                }
            }

            /**
            * Returns path to this Resource, relative to the contextRoot of the plugin
            *
            * @return {String} the path of this Resource, relative to the contextRoot of the plugin
            */
            config.prototype.getPath = function() {
                return this.path;
            }

            /**
            * Returns the description of this UIResource
            *
            * @return {String} the description of this UIResource
            */
            config.prototype.getDescription = function() {
                return this.description;
            }

            /**
            * Returns the type of this Resource.  Should be one of: script, css, jss, xml, xsl, services (for mapping
            * rules), or ljss
            *
            * @return {String} the type of this Resource
            */
            config.prototype.getType = function() {
                return this.type;
            }

            /**
            * Returns the (fully-qualified) name of the class represented by this Resource.  Applies only to Resources
            * of type 'script'.
            *
            * @return {String} the fully-qualified class name of this Resource
            */
            config.prototype.getClassName = function() {
                return this.className;
            }

            /**
            * Returns a string representing this object in the xml format specified by the component.xsd schema
            *
            * @param prepend {String} a string to be prepended to each line of the returned XML (useful for indenting)
            *
            * @returns {String} this Resources object as XML, as specified by the component.xsd schema
            */
            config.prototype.toString = function(prepend) {
                if(!prepend) {
                    prepend = "";
                }
                var ret = prepend + "<resource>\n";
                if(this.description) {
                    ret += prepend + "   <description>" + this.description + "</description>\n";
                }
                if(this.className) {
                    ret += prepend + "   <class_name>" + this.className + "</class_name>\n";
                }
                if(this.path) {
                    ret += prepend + "   <path>" + this.path + "</path>\n";
                }
                if(this.type) {
                    ret += prepend + "   <type>" + this.type + "</type>\n";
                }
                ret += prepend + "</resource>\n";
                return ret;
            }
        }
);